<?php

require_once dirname(__FILE__).'/etc/define.php';

// 报错
error_reporting(ERROR_REPORTING);
ini_set('display_errors', DISPLAY_ERRORS);

require_once ROOT.'/lib/G.php';
require_once ROOT.'/lib/page.php';

// 解析URL
/*
function parse_uri($uri) {
	preg_match('%^/(?P<controller>[a-z_][a-z0-9_]*?)(?:/+(?P<action>[a-z_][a-z0-9_]*?))?(?:\?(?P<query_string>.+?))?$%i', $uri, $m);
	return $m;
};
$path = parse_uri($_SERVER['REQUEST_URI']);
*/
$uri = $_SERVER['REQUEST_URI'];
$do = $_REQUEST['do'];
if(!$do)$do='homepage.index';
$p = explode('.', $do);
$path['controller']=$p[0];
$path['action']=$p[1];

if (!isset($path['controller'])) $path['controller'] = "homepage";
if (!isset($path['action'])) $path['action'] = "index";
define('CONTROLLER', $path['controller']);
define('ACTION', $path['action']);

if($path['controller']=='homepage')die('wrong');

if(!G::checkToken($_REQUEST['server_t'], $_REQUEST['token']) && $path['controller']!='data_cron')die('token');

// 实例化程序
$filename = ROOT."/app/{$path['controller']}.php";
if (!file_exists($filename)) G::http404("页面不存在");

require_once $filename;
$page = new $path['controller']();
$page->{$path['action']}();
